Go Back to website Click to download PDF

Manipulators

Q1 What are Manipulators? Describe different types of Manipulators? Which header file required to use some special manipulator?

Q2 WAP to print the following output using endl manipulator.

Output:

*

*

*

*

*

Q3 Explain the working of setw(w) manipulator. WAP to print the following output using setw(w) manipulator:

Output:

My Roll no is : 1241                        My Marks are : 56

Q4 Explain the working of setfill(c) manipulator. WAP to print the following output using setfill(c) manipulator:

Output:

##10

####4142

Q5 Explain the working of setprecision(n) manipulator. WAP to print the following output using setprecision(n) manipulator:

Input:

x=12.4766

y=134.543

Output:

12.48

134.54

Q6 Explain the working of dec, oct, hex  manipulators. WAP to convert decimal number into hexadecimal, octal.

Q7 Explain the working of setbase(b) manipulator. WAP to change the base of a decimal number into hexadecimal, octal.

 


 

Classes and Objects

Q1   What is OOPS? What is the Principle of OOP?

Q2 What are the basic Concepts of Object- Oriented Programming?

Q3 What private: int num1, num2, num3;

Member Function:

public: void input(), void sum()

Add private data member of the class ‘Math’ and display the output.

Q4 WAP to define a class ‘Student’ and define

Q5 its member function input() and output()is C++? How C++ is associated with OOP?

Q6 What is a class? How can we define a class?

Q7 What are Access Specifiers?

Q8 What are objects? How we can declare object of a class?

Q9 Define a class ‘Math’ with these specification:

Data Members:

Q10              outside the class with the help of scope resolution operator.

Q11              WAP to define a class ‘Student’ and calculate percentage of five students. (Hint: using array of objects).

private:

int rollno; float marks[],per;

          public:

                   get_data(),percent();

    Q10 WAP to define a class ‘Demo’ as per following description

          private: int num;

           public: void get_data(), void sum() (sum is a function which will add data member of two objects taking other object as an argument)

Q11 How can we pass object by reference to a member function of a class? WAP to swap data members of two objects.

Q12 What are inline functions? What is the use of inline function? WAP to find the      greatest of three numbers using inline function max().

 

 


 

Constructor And Destructor

Q1. What is constructor? What are the various features of constructor?

Q2. Define various types of constructor?

Q3. WAP to initialize the private data member of a class ‘Rectangle’ with given values and display the values of length, breadth;

L=10;

B=20;

Q4. WAP to define a class ‘Rectangle’ and calculate the area of different objects of ‘Rectangle’ class. Length and breadth should be initialized by parameterized constructor.

Q5. What is constructor overloading?

Q6. WAP to define a class ‘Rectangle’ having default constructor as well as parameterized constructor in it.

Q7. WAP to define a class ‘Rectangle’ and calculate the area of different objects of ‘Rectangle’ class in which 2nd object copies the value of length and breadth of 1st object.

Q8. What is Destructor? Give an example through program.

 


 

Friend Function Friend Class

Q1 What is friend function? What is the need of friend function?

Q2 How a friend functions of class is differ from a member function of a class?

Q3 WAP to define a class ‘demo’ and use its private data member in its friend function usedata().

Q4 WAP to define a class ‘demo’ that contains:

private:

data member :                 num1, num2;

public:

member function:            input();

                                      output();

Now, calculate the sum of num1 and num2 through a function sum();

Q5 WAP to define two classes ‘demo1’ and ‘demo2’ and add their private data members in a function which is the friend of both the classes.

Q6 WAP to find the greater of data members of two different classes.

Q7 What is friend class? What is the need of friend class?

Q8 WAP to swap the private data of two classes in a third friend class.

 


 

Static Data Member and Static Member Function

Q1. What is Static Data Member? What are properties of a static data member?

Q2. WAP to display number of objects created of a class.

Q3. WAP to define a class ‘Rectangle’ and calculate the area of rectangle and count that how many rectangles are created?

Q4. What is static member function?

Q5. WAP to declare a static member function void init() in class ‘Rectangle’ to initialize the static data member count and calculate the area of rectangles.

Q6. WAP to count that how many objects are created of a class and display the output.


 

Inheritance

Q1 Do as Described:

Class

private:int rollno;

char name[20];

 

public: get_data();

show_data();

 

Student

 

 

 

 

 

 

 

 

                               


 

Single Inheritance

Student

private: int rollno;

char name[20];

 

public: get_data();

show_data();

 

 

 

 

 

 

 

 

 

 


private: float marks[5];

 

public: get_marks();

percentage();

 

Marks

           

 

 

 

           

Answer the following:

i.                     If Marks also have the same name function as that of class Student then which function will be invoked by the object of class Marks.

ii.                   What is the syntax of calling the base class function if both the derived class and base class have same name function.


iii.                  

 

Multiple Inheritance

Student                                                                                                                       Teacher

private: int rollno;

char name[20];

 

public: get_data();

show_data();

 

private:char name[10];

float salary;

char sub;

public: get_data1();

show_data1();

 

 

 

 

 

 

 


School

private:int no_of_stu;

int no_of_teacher;

public:get_data2();

show_data2();

 

 

 

 

 

 

 


Answer the following:

i.                     If both the classes ‘Student’ and ‘School’ have the default constructor then which constructor will be called first?

ii.                   If both the classes ‘Teacher’ and ‘School’ have the default constructor as well as parameterized constructor then what is the order of constructor call?

iii.                 How can we call the base class parameterized constructor before the derived class parameterized constructor?

 


Multilevel:

private: int rollno;

char name[20];

public: get_data();

show_data();

 

                        Student

 

 

 

 

 


protected:int no_of_absentees;

public: get_data();

show_data();

 

 

Attendance

 

 

 

 

 


private:Float fees;

Float bal;

public:get_data();

cal_total_amt();

 

 

 

Accounts

 

 

 

 

Answer the following:

i.                     Can object of class ‘Accounts’ directly access the get_data() function of ‘Student’ class.

ii.                   If ‘a1’ is the object of class ‘Accounts’ then this will generate the error or not ‘ a1.Student::get_data();’ if yes, Explain why?


 

Hierarchical:

Student

protected:int rollno;

char name[20];

public:get_data();

show_data();

 

 

 

 

 

 

 


private:char game_name[];

float score;

public:get_score();

show_score();

 

private:float marks[];

 

public: get_marks();

percentage();

 

                                          Marks                                                                              Sports

 

 

 

 

 

 

Answer the following:

i.                     Name the member functions which are accessible by the object of class ‘Sports’.

ii.                   How much memory is allocated to the object of class ‘Marks’?

iii.                 Is following statements generate the error, if yes explain why.

Sports s1;

s1.get_marks();

cout<<s1.rollno;


 

Hybrid

public:

void show()

A

 

 

public:

void show2()

 

 


public:

void show1()

                                  B                                                                                                    C

public:

void show3()

 

 

 

 


                                                                                        D

 

 

 

                  Answer the following:

i.                     Following statement will generate any error or not? If yes, Explain why?

D d1;

d1.show();

ii.                   How can we call the show function of class ‘B’?

iii.                 Can D call the member function of class ‘A’?

iv.                 If ‘d1’ is the object of class ‘D’ then the following call will generate any error?

d1.A::show();

 


Hybrid:

protected:char name[];

int rollno;

public:get_data();

show_data();

Student

 

 

 

 

 

 


Test

protected:

float marks[];

public: gettest();

showtest();

 

                                               

private:float total,avg;

public:get_result();

show_result();

 

private:char city[];

public:get_add();

show_add();

 

 


                                                                                                                        Address

 

 

                      Result

 

 

 

                                                     


 

Polymorphism

Virtual Function Pure Virtual Function

Q1 What is Polymorphism? How do we achieve polymorphism?

Q2 What is virtual function? What are the basics rules? Explain with help of a Program.

Q3 WAP to define a class ‘Shape’ which contains two virtual functions area() and perimeter() and its derived classes ‘Rectangle’ and ‘Square’ calculate their area and perimeter with extending the definition of virtual function.

Q4 What is Pure Virtual function? How it is different from Virtual function?

Q5 WAP to define a class ‘Shape’ which contains two function area() and perimeter() and its mandatory to its derived classes to calculate the area and perimeter of their shape.

Operator Overloading

Q1   WAP to add data members of two objects of a class using operator overloading with friend function.

Q2   WAP to find the greatest of two objects using operator overloading with friend function

Q3   WAP to check whether two objects are equal or not using operator overloading with friend function

Function Overloading

Q1 WAP to add two integer, two float through a user defined function sum() numbers are passed as arguments.

Q2 WAP to find the area of rectangle, square through a function area(), using the concept of function overloading.


 

Dynamic Memory Allocation

Q1 What is dynamic Memory allocation? How can we allocate the memory at runtime?

Q2 How new and delete operators works? Explain with the help of a program.

Q3 WAP to allocate the memory to two integer variables at run time and display their sum.

Q4 WAP to allocate the memory space to an array at run time and display the reverse of it.

Q5 WAP to define a class ‘Demo’ with private data members num and public member function input() and display() now allocates the memory to the class variables at run time.

Q6 WAP to get two integers at run time and swapped their values.

Q7 WAP to find mn where all the variables used gets memory at run time.

Q8 WAP to find the largest element of an array through dynamic memory allocation concept.

 


 

File Handling

Q1. What is File Handling?

Q2. Which library file of C++ provides facilities for the file input/output operations?

Q3. Name three stream classes commonly used for the file I/O?

Q4. What are the two ways of opening the file?

Q5. What do you understand by file modes? What are the various file modes used in file handling?

Q6. WAP to get a number from the user and store it into the file.

Q7. WAP to get two numbers from the user and store the numbers into the file with spaces.

Q8. WAP to get roll number and name of a student and store the data into a file.

Q9. WAP to display a number that is already stored in the file.

Q10. WAP to read roll number and name of a student from a file and display the content on the screen.

Q11. WAP to write two or more lines into the file?

(Hint: using getline() function)

Q12. WAP to count that how many words, vowels and lines are stored in a file?

Q13. WAP to write a number and a string into a file name ‘first.txt’ and copy the contents into a file name ‘second.txt’ and display the content of file ‘second.txt’ on the monitor screen.

Q14. WAP to find the current position of the put pointer and move the cursor any specified  location to write the data.

Q15. WAP to find the current position of the get pointer and move the cursor to that location for reading the data.

Q16. WAP to open a file in both read and write mode.

Q17 WAP to read the roll no. and name of the student from console and save the record into the file through classes.

Q18. WAP to read the roll no. and name of the student from a file and print it on the screen.

Q19. WAP to modify the records stored in a file.

Q20.WAP to search in a file having records maintained through classes.

Q21. WAP to delete the records from a file.

Q22. WAP to add information about the student in an already existing file?

(hint: open a file in append mode)


 

Exception Handling

Q1 What are the different types of bugs a program can have? And what are exceptions?

Q2 Describe the basics of Exception Handling and its mechanism.

Q3 WAP to input two numbers from the user divide their difference by 1st number and display the output? (hint: difference might be zero handle the exception)

Q4 WAP to catch the exception as per the throw statement. (hint: Multiple catch)

Q5 WAP to catch all the exception raises by the try block.

Q6 How can we re-throw an exception? WAP to demonstrate it.

Q7 WAP to accept an integer array from the user and display its element, Raise Exception if array is out of bound.


 

Template

Q1. What is generic programming? Explain the feature of ‘Template’ in C++.

Q2. What is class template? Explain with an example.

Q3. WAP to define a class with two generic data types and display their output through a member function.

Q4. What is function template? Explain with an example.

Q5. WAP to swap two values by passing arguments of different data type to every function call through function template.

Q6. Describe overloading of template functions.

Q7. WAP to overload a show() template function.